/*
 *    Copyright (c) 2018-2025, st All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: st
 */

package com.mkh.st.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mkh.st.admin.api.dto.TenantDTO;
import com.mkh.st.admin.api.entity.SysTenant;
import com.mkh.st.admin.api.vo.TenantSaveVO;
import com.mkh.st.admin.api.vo.TenantVO;
import com.mkh.st.admin.service.SysTenantService;
import com.mkh.st.common.core.util.R;
import com.mkh.st.common.security.annotation.Inner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 租户管理
 *
 * @author st
 * @date 2019-05-15 15:55:41
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tenant")
@Api(value = "tenant", tags = "租户管理")
public class SysTenantController {

	private final SysTenantService sysTenantService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param vo 租户
	 * @return
	 */
	@GetMapping("/getSysTenantPage")
	@ApiOperation(value = "租户分页查询", notes = "租户分页查询")
	public R<IPage<TenantDTO>> getSysTenantPage(Page page, TenantVO vo) {
		return sysTenantService.getSysTenantPage(page,vo);
	}

	/**
	 * 通过id查询租户
	 * @param id id
	 * @return R
	 */
	@GetMapping("/getInfoById")
	@ApiOperation(value = "租户详情", notes = "租户详情")
	public R<SysTenant> getById(@RequestParam Long id) {
		return R.ok(sysTenantService.getById(id));
	}

	/**
	 * 新增/修改租户
	 * @param
	 * @return R
	 */
	@PostMapping("/saveTenantInfo")
	@ApiOperation(value = "租户信息保存", notes = "租户信息保存")
	public R<Boolean> saveTenantInfo(@RequestBody @Valid TenantSaveVO vo) {
		return sysTenantService.saveTenantInfo(vo);
	}



	/**
	 * 查询全部有效的租户
	 * @return
	 */
	@Inner(value = false)
	@GetMapping("/list")
	@ApiOperation(value = "正常租户集合", notes = "正常租户集合")
	public R list() {
		return R.ok(sysTenantService.getNormallist());
	}



}
